﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Seeker.DAL.Interface;
using Seeker.Model;
using Seeker.Model.Interface;

namespace Seeker.DAL.Admin
{
    public class AGroup : IGetAdminGroupInfo, ISetAdminGroupInfo, IDisposable
    {
        private SqlCommand cmd = new SqlCommand();

        public AGroup()
        {
            cmd.Connection = new SqlConnection(SqlHelper.AdminConnectionStr);
            cmd.Connection.Open();
        }


        /// <summary>
        /// 获取组列表
        /// </summary>
        /// <returns></returns>
        public List<IAdminGroupInfo> GetList()
        {
            List<IAdminGroupInfo> adminGroupList = new List<IAdminGroupInfo>();
            SqlDataReader dr;

            cmd.CommandText = "SELECT GID, [NAME] FROM AUSER_GROUPS_INFO";
            cmd.CommandType = CommandType.Text;
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                adminGroupList.Add(new AGroupModel()
                {
                    GID = (int)dr["GID"],
                    Name = dr["NAME"].ToString()
                });
            }

            dr.Close();

            return adminGroupList;
        }


        /// <summary>
        /// 按分组ID删除相关信息
        /// </summary>
        /// <param name="gid">分组ID</param>
        /// <returns></returns>
        public bool Delete(int gid)
        {
            return false;
        }


        /// <summary>
        /// 按多个分组ID删除相关信息
        /// </summary>
        /// <param name="gids">多个分组ID，如：1,2,3</param>
        /// <returns></returns>
        public bool Delete(string gids)
        {
            return false;
        }


        /// <summary>
        /// 更新单个分组信息
        /// </summary>
        /// <param name="info">分组信息</param>
        /// <returns></returns>
        public bool Update(IAdminGroupInfo info)
        {
            return false;
        }


        /// <summary>
        /// 更新多个分组信息
        /// </summary>
        /// <param name="info">分组信息</param>
        /// <returns></returns>
        public bool Update(List<IAdminGroupInfo> info)
        {
            return false;
        }


        /// <summary>
        /// 添加单个分组信息
        /// </summary>
        /// <param name="info">分组信息</param>
        /// <returns></returns>
        public bool Add(IAdminGroupInfo info)
        {
            return false;
        }


        /// <summary>
        /// 添加多个分组信息
        /// </summary>
        /// <param name="info">分组信息</param>
        /// <returns></returns>
        public bool Add(List<IAdminGroupInfo> info)
        {
            return false;
        }

        public void Dispose()
        {
            if (cmd.Connection.State == ConnectionState.Open)
            {
                cmd.Connection.Close();
            }

            cmd.Dispose();
        }
    }
}
